﻿#include "Style.h"
#include "Log.h"
// 定义 QSS 文件路径
const QString Style::DARKSTYLE = ":/rc/darkstyle.qss";
const QString Style::LIGHTSTYLE = ":/rc/lightstyle.qss";
const QString Style::BLUESTYLE = ":/styles/blue.qss";
const QString Style::NONESTYLE = "";

// 加载 QSS 文件内容
QString Style::LoadQSS(const QString& filePath)
{
    QFile file(filePath);
    if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
        Logger::getInstance().warning() << QString("Failed to open QSS file:") << filePath;
        return QString{};
    }
    QString qss = file.readAll();
    file.close();
    return qss;
}

// 加载样式
void Style::LoadStyle(StyleType type)
{
    QString qssFilePath;

    switch (type) {
    case Dark:
        qssFilePath = DARKSTYLE;
        break;
    case Light:
        qssFilePath = LIGHTSTYLE;
        break;
    case BLUE:
        qssFilePath = BLUESTYLE;
        break;
    case NONE:
        qssFilePath = NONESTYLE;
        break;
    default:
        qWarning() << "Unknown style type:" << type;
        return;
    }

    QString qss;
    if (!qssFilePath.isEmpty()) {
        qss = LoadQSS(qssFilePath);
    }

    // 应用样式
    qApp->setStyleSheet(qss);
}
